package leetcode.middle._2178;

import java.util.ArrayList;
import java.util.List;

/**
 * @author mgl
 * @version 1.0
 * @description LeetCode第2178道题：将一个数拆分成最多数目的正偶数之和
 * @date 2023/7/6 23:42
 */
public class MaximumEvenSplit {
    public List<Long> maximumEvenSplit(long finalSum) {
        if (finalSum % 2 != 0) return new ArrayList<Long>();

        List<Long> list = new ArrayList<>();
        int index = 0;
        for (long i = 2; 0 <= finalSum; i += 2) {

            if (finalSum - i < 0) {
                list.set(index - 1, finalSum + list.get(index - 1));
                break;
            } else {
                list.add(i);
                finalSum -= i;

                index++;
            }
        }

        return list;
    }
}
